<?php
/*
 * @Author: your name
 * @Date: 2020-11-11 10:49:01
 * @LastEditTime: 2020-12-23 15:06:15
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙规则日志
 * @FilePath: /special/application/api/service/netfilter/FirewallRuleService.php
 */
namespace app\api\service\netfilter;

use app\common\definition\HostDefinition;
use app\common\exception\CustomException;
use think\Db;
use think\Exception;

class FirewallRuleService {
    
    //主机id
    protected $host_id;
    public $host_os;
    protected $nowtime;

    function __construct($hostkey)
    {
        $host = Db::name('host')->field('h.os,hmr.*')->alias('h')->leftJoin('HostModuleRelation hmr', 'hmr.host_id=h.id')->where('hostkey', $hostkey)->find();

        if (empty($host) || !isset($host['netfilter']))
        {
           throw new CustomException('未找到该主机', 422);
        }
        
        if ($host['os'] == HostDefinition::UNKNOW_OPERATION_SYSTEM)
        {
            throw new CustomException('不能识别该主机系统', 422);
        }

        if ($host['netfilter'] != 1)
        {
           throw new CustomException('该主机未开启模块', 422);
        }

        
        $this->nowtime = time();
        $this->host_id = $host['host_id'];
        $this->host_os = $host['os'];
    }
    
}